<template>
	<view class="ayi-page">
		<navigation :isBack="true" title="订单" titleTintColor="#fff"><text slot="back" class="iconfont">&#xe63d;</text></navigation>
		<view class="my-list">
			<view class="my-item" v-show="!empty(listData)" v-for="(item, index) in listData" :key="index">
				<view>流水号：{{ item.show_id }}</view>
				<view>类型：{{ item.tpyeName }}</view>
				<view>金额：{{ item.cash }}</view>
				<view>描述：{{ item.remark }}</view>
				<view>时间：{{ datestr(item.created) }}</view>
			</view>
			<view class="my-item" v-show="empty(listData)"><view>暂无数据</view></view>
		</view>
		<text class="loading-text">{{ loadingType === 0 ? contentText.contentdown : loadingType === 1 ? contentText.contentrefresh : contentText.contentnomore }}</text>
		<Tabbar :indexpage="-1"></Tabbar>
	</view>
</template>

<script>
import { Tools, Config, URL, Net, VueTools } from '@/common/tools.js';
import navigation from '@/components/navigation.vue';
import Tabbar from '@/components/tabbar.vue';
export default {
	components: { Tabbar, navigation },
	data() {
		return {
			listData: [], //显示的数据
			signId: '',
			sTime: '',
			eTime: '',
			page:1,
			loadingType: 0,
			contentText: {
				contentdown: '上拉显示更多',
				contentrefresh: '正在加载...',
				contentnomore: '没有更多数据了'
			}
		};
	},
	methods: {
		/**
		 * 返回上一页
		 */
		back(){
			// #ifndef H5
			uni.navigateBack();
			this.Tab.getInstance().show();
			// #endif
			// #ifdef H5
			history.back();
			// #endif
		},
		/**
		 * 获取列表的数据
		 * @param {type}  isload 是否加载更多true是更多
		 */
		getTransactionlist(isload=false){
			 let that = this;
			 Net.ayiHttp(
			 	URL.MMNU_SHOWACCTLIST,
			 	'{"signid":"' + that.signId + '","stime":"' + that.sTime + '","etime":"' + that.eTime + '","page":"' + that.page + '"}',
			 	function(res) {
			 		if (res.code == Config.SUCCESS_CODE) {
			 			//成功的逻辑
			 			let data = Tools.aesDecodeToJson(res.data);
			 			console.log('处理好了的', data);
						if (isload) {
						  if (data.rowset.length > 0) {
						    that.listData = that.listData.concat(data.rowset);
							that.loadingType=0;
						  } else {
							  that.loadingType=2;
						    VueTools.toastNo("数据已经加载完成");
						  }
						} else {
						  that.listData = data.rowset;
						}
			 		} else if (res.code == Config.FAIL_CODE) {
			 			VueTools.toastNo(res.message);
			 		} else if (res.code == Config.LOGIN_CODE) {
			 			uni.navigateTo({
			 				url: "/pages/my/login/login"
			 			});
			 		}
					uni.stopPullDownRefresh();
			 	},
			 	function(err) {
			 		console.log('error:', err);
					uni.stopPullDownRefresh();
			 	}
			 );
			 		
		}
	},
	onLoad(option) {
		this.signId = option.signid;
		this.sTime = option.stime;
		this.eTime = option.etime;
		 if (Tools.isEmpty(this.signId)) {
		     this.back();
		      return;
		  }
		  this.getTransactionlist();
	},
	onUnload() {},
	onReachBottom() {
		if(this.loadingType!=0){
			return false;
		}
		this.loadingType=1;
		this.page++;
		this.getTransactionlist(true);
	},
	onPullDownRefresh(){
		this.loadingType=0;
		this.page=1;
		this.getTransactionlist();
	}
};
</script>

<style lang="scss">
.my-list{
	
}
.my-item {
	border-bottom: 1px solid #e8e9ec;
	display: flex;
	flex-direction: column;
	padding: 16rpx;
	font-size: 28rpx;
	color: rgba(0, 0, 0, 0.4);
}
.loading-text {
	height: 80rpx;
	line-height: 80rpx;
	font-size: 30rpx;
	display: flex;
	flex-direction: row;
	justify-content: space-around;
}
</style>
